<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page
import="com.example.demo.grbkxt.model.Blog" %> <%@ page
import="com.example.demo.grbkxt.model.User" %>
<!DOCTYPE html>
<html>
  <head>
    <title>编辑博客</title>
    <%@ include file="/WEB-INF/views/common/header.jsp" %>
    <style>
      .container {
        width: 80%;
        margin: 0 auto;
        padding: 20px;
      }
      .form-group {
        margin: 15px 0;
      }
      .form-group label {
        display: block;
        margin-bottom: 5px;
      }
      .form-group input[type="text"],
      .form-group textarea,
      .form-group select {
        width: 100%;
        padding: 8px;
        border: 1px solid #ddd;
      }
      .form-group textarea {
        height: 200px;
      }
      .btn {
        padding: 8px 15px;
        margin-right: 10px;
        cursor: pointer;
      }
      .btn-primary {
        background-color: #4caf50;
        color: white;
        border: none;
      }
      .btn-secondary {
        background-color: #666;
        color: white;
        border: none;
      }
    </style>
  </head>
  <body>
    <div class="container">
        <h1>编辑博客</h1>
        <% 
            Blog blog = (Blog)request.getAttribute("blog");
            System.out.println("Edit JSP - Blog Category: " + blog.getCategory()); // 添加调试日志
        %>
        <form action="${pageContext.request.contextPath}/blog/update" method="post">
            <input type="hidden" name="id" value="<%= blog.getId() %>">
            <div class="form-group">
                <label>标题：</label>
                <input
                    type="text"
                    name="title"
                    value="<%= blog.getTitle() %>"
                    required
                />
            </div>
            <div class="form-group">
                <label>内容：</label>
                <textarea name="content" required><%= blog.getContent() %></textarea>
            </div>
            <div class="form-group">
                <label>分类：</label>
                <select name="category" required>
                    <option value="技术" <%= ("技术".equals(blog.getCategory())) ? "selected" : "" %>>技术</option>
                    <option value="生活" <%= ("生活".equals(blog.getCategory())) ? "selected" : "" %>>生活</option>
                    <option value="随笔" <%= ("随笔".equals(blog.getCategory())) ? "selected" : "" %>>随笔</option>
                    <option value="其他" <%= ("其他".equals(blog.getCategory())) ? "selected" : "" %>>其他</option>
                </select>
            </div>
            <div class="form-group">
                <label>
                    <input type="checkbox" name="adminOnly" <%= blog.isAdminOnly() ?
                    "checked" : "" %>> 仅管理员可见
                </label>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary">保存</button>
                <a href="${pageContext.request.contextPath}/blog/admin" class="btn btn-secondary">返回</a>
            </div>
        </form>
    </div>
</body>
</html>
